package com.robert.mvp.base;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.robert.mvp.utils.ReflectUtil;

/**
 * Des:
 *
 * @Author: cpf 遇到动态的，有数据请求和处理的页面，再让 MVP 出马
 * @date: ${date} ${hour} ${minute}
 * @email: 2227039052@qq.com
 */
public abstract class BaseMvpActivity
        <T extends BasePresenter, M extends BaseModel> extends BaseActivity {
    protected T mPresenter;
    protected M mModel;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter = ReflectUtil.getT(this, 0);
        mModel = ReflectUtil.getT(this, 1);
        mPresenter.onAttach(mModel, this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        loadData();
    }

    protected abstract void loadData();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.onDetach();
    }
}
